import { Injectable } from '@angular/core';
import { BaseService } from './base.service';
import { PersonnelInfo } from '../models';
@Injectable({
  providedIn: 'root'
})
export class PersonnelService extends BaseService {
  //添加人员
  createUser(params: PersonnelInfo) {
    const url = 'api/user';
    return this.post(url, params);
  }
  //编辑人员
  updateUser(params: PersonnelInfo) {
    const url = 'api/user';
    return this.put(url, params);
  }
  //删除人员
  deleteUser(Id) {
    const url = 'api/user';
    return this.delete(`${url}/${Id}`);
  }
  //人员详情
  getUserInfoById(Id) {
    const url = 'api/user';
    return this.get(`${url}/${Id}`);
  }
  //人员列表
  queryUsers(params: {
    name?: string;
    phone?: string;
    employeeNo?: string;
    gender?: string;
    beginTime?: string;
    endTime?: string;
    pageIndex?: number;
    countOfPage?: number;
    parentId?: string;
  }) {
    const url = 'api/user';
    return this.get(url, { params });
  }

  // 获取工号
  getemployeeNo() {
    const url = 'api/orgCodeRule/gcode'
    const orgCodeRuleName = '员工工号'
    return this.get(url, {
      params: {
        orgCodeRuleName
      }
    })
  }
  // 保存工号
  saveUseremployeeNo(seedId) {
    const url = 'api/organization'
    const id = localStorage.getItem('orgid') + "/orgCodeSeed"
    return this.put(`${url}/${id}/${seedId}`)
  }
  // 查询超级权限
  getSuperPersonlist() {
    const url = 'api/user?superPermit=true'
    return this.get(url)
  }

  // 新增修改超级权限
  setSuper(account) {
    const url = 'api/account';
    if (account.superPermits && account.superPermits.length == 0) {
      account.superPermits = null;
    }
    return this.put(url, account)
  }
}
